//====================================================================================================
// Includes
//====================================================================================================

#include "GuardianIdle.h"

#include "Guardian.h"

//====================================================================================================
// Class Definitions
//====================================================================================================

GuardianIdle::GuardianIdle(Guardian* pOwner)
	: GuardianState(pOwner, "Idle")
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

GuardianIdle::~GuardianIdle()
{
	// Empty
}

//----------------------------------------------------------------------------------------------------

void GuardianIdle::Load()
{
	//mSprite.Add("halo_sprite.png");

	mSprite.Add("guardian_idle.png");
}

//----------------------------------------------------------------------------------------------------

void GuardianIdle::Unload()
{
	mSprite.Unload();
}

//----------------------------------------------------------------------------------------------------

void GuardianIdle::Update(float deltaTime)
{
	// Update sprite
	mSprite.Update(deltaTime);

	// State transitions
	if (Input_IsKeyPressed(Keys::UP))
	{
		mpOwner->ChangeState(AS_Jump);
	}
	else if (Input_IsKeyDown(Keys::RIGHT) || Input_IsKeyDown(Keys::LEFT))
	{
		mpOwner->ChangeState(AS_Walk);
	}
}

//----------------------------------------------------------------------------------------------------

void GuardianIdle::Render(const SVector2& offset)
{
	const int kTextureWidth = mSprite.GetWidth();
	const int kTextureHeight = mSprite.GetHeight();
	const SVector2 ownerPos(mpOwner->GetPosition());
	const SVector2 renderPos(ownerPos.x - (kTextureWidth * 0.5f), ownerPos.y - kTextureHeight);
	bool facingLeft = mpOwner->IsFacingLeft();
	mSprite.SetPosition(renderPos - offset);
	mSprite.SetFlipH(facingLeft);
	mSprite.Render();
}

//----------------------------------------------------------------------------------------------------

void GuardianIdle::Enter()
{
	mSprite.Play(4.0f, true);
}

//----------------------------------------------------------------------------------------------------

void GuardianIdle::Exit()
{
	mSprite.Stop();
	mSprite.Reset();
}

//----------------------------------------------------------------------------------------------------

SRect GuardianIdle::GetBoundingBox() const
{
	const SVector2 pos(mpOwner->GetPosition());
	return SRect
	(
		pos.x - 16.0f,
		pos.y - 56.0f,
		pos.x + 16.0f,
		pos.y
	);
}